<template>
	<view class="flex bg-white rounded-lg pt-30 items-start pb-20">
		<view class="flex-1 flex flex-wrap" v-if="isAch == 1">
			<view class="flex flex-col w-[33%] mb-10 justify-center items-center" v-for="(e,i) in anchorAbiltyList" :key="i"
				@click="onPath(e.router)">
				<ImageBoxVue :src="e?.icon" width="97rpx" height="67rpx"></ImageBoxVue>
				<text class="mt-8">{{e.label}}</text>
			</view>
		</view>
		<view class="flex-1 flex flex-wrap" v-else>
			<view class="flex flex-col w-[20%] mb-10 justify-center items-center" v-for="(e,i) in abiltyList" :key="i"
				@click="onPath(e.router)">
				<ImageBoxVue :src="e.icon" width="97rpx" height="67rpx"></ImageBoxVue>
				<text class="mt-8">{{e.label}}</text>
			</view>
		</view>
		<view class="flex flex-col justify-between" v-if="isAch == 1">
			<ImageBoxVue src="/static/user/open_live.png" width="262rpx" height="81rpx" @click="createRoom">
			</ImageBoxVue>
			<ImageBoxVue src="/static/user/open_mike.png" width="262rpx" height="81rpx"></ImageBoxVue>
			<ImageBoxVue src="/static/user/aptitude.png" width="262rpx" height="81rpx"
				@click="onPath('/pages/user/aptitude')"></ImageBoxVue>
			<ImageBoxVue src="/static/user/solve.png" width="262rpx" height="81rpx"
				@click="onPath('/pages/user/tieBaProblem')"></ImageBoxVue>
			<ImageBoxVue src="/static/user/post.png" width="262rpx" height="81rpx" @click="onPath('/pages/user/toBeSolved')">
			</ImageBoxVue>
			<ImageBoxVue src="/static/user/answer.png" width="262rpx" height="81rpx" @click="handleAnswer"></ImageBoxVue>
		</view>
	</view>
	<!-- 创建直播 -->
	<uni-popup ref="createRoomRef">
		<view class="p-30 bg-white border-[#FFCE99] border-solid rounded-lg w-[690rpx]">
			<view class="mb-20">
				<text class="text-sm font-bold">创建直播</text>
			</view>
			<view class="bg-[#EBF5FB] p-20">
				<uni-easyinput class="my-10 p-10 bg-white" v-model="query.name" placeholder="标题"></uni-easyinput>
				<uni-easyinput class="my-10 p-10 bg-white" v-model="query.describe" type="textarea"
					placeholder="介绍"></uni-easyinput>
				<uni-easyinput class="my-10 p-10 bg-white" v-model="query.tipstr" type="textarea"
					placeholder="标签,多个标签用,隔开"></uni-easyinput>
				<view class="w-full flex items-center justify-between my-10 p-10 bg-white">
					<view class="uni-list-cell-db">{{query.sts==0?'公麦':'私麦'}}</view>
					<switch :checked="query.sts==0" style="transform:scale(0.7)" @change="e=>query.sts=e.detail.value?0:1" />
				</view>
				<view class="w-full flex items-center justify-between my-10 p-10 bg-white">
					<view class="uni-list-cell-db">{{query.pays==0?'蓝钻':'红钻'}}</view>
					<switch checked :checked="query.pays==0" style="transform:scale(0.7)"
						@change="e=>query.pays=e.detail.value?0:1" />
				</view>
				<button type="primary" class="rounded-full mt-20 w-full" @click="anchorCreateRoom">创建直播</button>
			</view>
		</view>
	</uni-popup>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	const {
		isAch
	} = defineProps(['isAch'])
	import userApi from '@/apis/apiList/userApi'
	import liveApi from '@/apis/apiList/liveApi'
	import {
		debounce
	} from '@/config/publicFun.js'
	const createRoomRef = ref(null)
	const query = ref({
		name: `xxx的直播间`,
		describe: `xxx的直播间`,
		tipstr: "塔罗牌",
		sts: 0,
		pays: 0
	})
	const abiltyList = ref([{
		icon: "/static/user/files.png",
		label: "我的档案",
		router: "/pages/views/archiveList"
	}, {
		icon: "/static/user/record.png",
		label: "浏览记录",
		router: "/pages/test/collect?type=view"
	}, {
		icon: "/static/user/settled.png",
		label: "入驻平台",
		router: "/pages/user/settledProcess"
	}, {
		icon: "/static/user/collect.png",
		label: "赞与收藏",
		router: "/pages/test/collect?type=collect"
	}, {
		icon: "/static/user/bug.png",
		label: "问题反馈",
		router: "/pages/test/report?title=问题反馈&type=1"
	}, {
		icon: "/static/user/report.png",
		label: "举报主播",
		router: "/pages/test/report"
	}, {
		icon: "/static/user/study.png",
		label: "学习资料",
		router: "/pages/test/my-lesson"
	}, {
		icon: "/static/user/study.png",
		label: "VIP特权",
		router: "/pages/user/vip"
	}, {
		icon: "/static/user/study.png",
		label: "充值",
		router: "/pages/views/charge"
	}, ])
	const anchorAbiltyList = ref([{
		icon: "/static/user/files.png",
		label: "我的档案",
		router: "/pages/views/archiveList"
	}, {
		icon: "/static/user/record.png",
		label: "浏览记录",
		router: "/pages/test/collect?type=view"
	}, {
		icon: "/static/user/collect.png",
		label: "赞与收藏",
		router: "/pages/test/collect?type=collect"
	}, {
		icon: "/static/user/bug.png",
		label: "问题反馈",
		router: "/pages/test/report?title=问题反馈&type=1"
		// }, {
		// 	icon: "/static/user/report.png",
		// 	label: "举报主播",
		// 	router: ""
	}, {
		icon: "/static/user/study.png",
		label: "学习资料",
		router: "/pages/test/my-lesson"
	}, {
		icon: "/static/user/study.png",
		label: "VIP特权",
		router: "/pages/user/vip"
	}, {
		icon: "/static/user/study.png",
		label: "充值",
		router: "/pages/views/charge"
	}, {
		icon: "/static/user/study.png",
		label: "我的证书",
		router: "/pages/user/certificate"
	}, {
		icon: "/static/user/study.png",
		label: "提现",
		router: "/pages/test/withdraw"
	}, ])

	const onPath = (router) => {
		uni.navigateTo({
			url: router
		})
	}
	// 抢答问题
	const handleAnswer = debounce(() => {
		const opt = {
			id: uni.getStorageSync('anchor').id
		}
		userApi.getPossatpstquick(opt).then(res => {
			if (res.data.posts == 1) {
				uni.navigateTo({
					url: `/pages/user/quickAnswerPsychology?id=${res.data.id}`
				})
			} else if (res.data.posts == 2) {
				uni.navigateTo({
					url: `/pages/user/quickAnswer?id=${res.data.id}`
				})
			} else if (res.data.posts == 3) {
				if (res.data.exmk == 0) {
					uni.navigateTo({
						url: `/pages/user/quickAnswer?id=${res.data.id}`
					})
				} else if (res.data.exmk == 1) {
					uni.navigateTo({
						url: `/pages/user/quickAnswerCard1?id=${res.data.id}`
					})
				} else if (res.data.exmk == 2) {
					uni.navigateTo({
						url: `/pages/user/quickAnswerCard2?id=${res.data.id}`
					})
				}
			}
		})
	})

	// 开启直播
	const createRoom = () => {
		createRoomRef.value.open()
	}
	const anchorCreateRoom = () => {
		const params = {
			"anchor.id": uni.getStorageSync('anchor').id,
			...query.value
		}
		liveApi.anchorCreateRoom(params).then(res => {
			console.log(res);
			createRoomRef.value.close()
			uni.showToast({
				icon: "none",
				title: "开启成功"
			})
			uni.navigateTo({
				url: `/pages/live/liveRoom?id=${res.data.id}`
			})
		})
	}
</script>

<style>
</style>